﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package org.aswing {
    import org.aswing.geom.*;

    public class ScrollPaneLayout extends EmptyLayout {

        public static const TOP_LEFT:int = 3;
        public static const TOP_RIGHT:int = 2;
        public static const BOTTOM_LEFT:int = 1;
        public static const BOTTOM_RIGHT:int = 0;

        private var style:int;

        public function ScrollPaneLayout(_arg1:int=0){
            this.style = _arg1;
        }
        override public function minimumLayoutSize(_arg1:Container):IntDimension{
            var _local2:JScrollPane;
            var _local3:IntDimension;
            var _local4:Insets;
            var _local5:Viewportable;
            if ((_arg1 is JScrollPane)){
                _local2 = JScrollPane(_arg1);
                _local3 = this.getScrollBarsSize(_local2);
                _local4 = _local2.getInsets();
                _local3 = _local3.increaseSize(_local4.getOutsideSize());
                _local5 = _local2.getViewport();
                if (_local5 != null){
                    _local4 = _local5.getViewportPane().getInsets();
                    _local3.increaseSize(_local4.getOutsideSize());
                    _local3.increaseSize(_local5.getViewportPane().getMinimumSize());
                };
                return (_local3);
            };
            return (super.minimumLayoutSize(_arg1));
        }
        private function getScrollBarsSize(_arg1:JScrollPane):IntDimension{
            var _local2:JScrollBar = _arg1.getVerticalScrollBar();
            var _local3:JScrollBar = _arg1.getHorizontalScrollBar();
            var _local4:IntDimension = new IntDimension();
            if (((!((_local2 == null))) && ((_arg1.getVerticalScrollBarPolicy() == JScrollPane.SCROLLBAR_ALWAYS)))){
                _local4.width = _local2.getPreferredWidth();
            };
            if (((!((_local3 == null))) && ((_arg1.getHorizontalScrollBarPolicy() == JScrollPane.SCROLLBAR_ALWAYS)))){
                _local4.height = _local3.getPreferredHeight();
            };
            return (_local4);
        }
        override public function preferredLayoutSize(_arg1:Container):IntDimension{
            var _local2:JScrollPane;
            var _local3:Insets;
            var _local4:IntDimension;
            var _local5:Viewportable;
            if ((_arg1 is JScrollPane)){
                _local2 = JScrollPane(_arg1);
                _local3 = _local2.getInsets();
                _local4 = _local3.getOutsideSize();
                _local4.increaseSize(this.getScrollBarsSize(_local2));
                _local5 = _local2.getViewport();
                if (_local5 != null){
                    _local4.increaseSize(_local5.getViewportPane().getPreferredSize());
                };
                return (_local4);
            };
            return (super.preferredLayoutSize(_arg1));
        }
        override public function layoutContainer(_arg1:Container):void{
            var _local2:JScrollPane;
            var _local3:Viewportable;
            var _local4:JScrollBar;
            var _local5:JScrollBar;
            var _local6:IntDimension;
            var _local7:Insets;
            var _local8:IntRectangle;
            var _local9:IntDimension;
            var _local10:IntDimension;
            var _local11:int;
            var _local12:int;
            var _local13:int;
            var _local14:int;
            var _local15:int;
            var _local16:int;
            var _local17:int;
            var _local18:int;
            var _local19:Component;
            var _local20:int;
            var _local21:int;
            var _local22:IntDimension;
            var _local23:IntDimension;
            var _local24:int;
            var _local25:int;
            if ((_arg1 is JScrollPane)){
                _local2 = JScrollPane(_arg1);
                _local3 = _local2.getViewport();
                _local4 = _local2.getVerticalScrollBar();
                _local5 = _local2.getHorizontalScrollBar();
                _local6 = _local2.getSize();
                _local7 = _local2.getInsets();
                _local8 = _local7.getInsideBounds(_local6.getBounds());
                _local9 = _local4.getPreferredSize();
                _local10 = _local5.getPreferredSize();
                _local19 = _local3.getViewportPane();
                _local20 = 0;
                _local21 = 0;
                if (_local2.getHorizontalScrollBarPolicy() == JScrollPane.SCROLLBAR_ALWAYS){
                    _local21 = _local10.height;
                };
                if (_local2.getVerticalScrollBarPolicy() == JScrollPane.SCROLLBAR_ALWAYS){
                    _local20 = _local9.width;
                };
                _local3.setViewportTestSize(new IntDimension((_local8.width - _local20), (_local8.height - _local21)));
                _local22 = _local3.getExtentSize();
                _local23 = _local3.getViewSize();
                _local14 = _local9.width;
                _local18 = _local10.height;
                if (_local2.getHorizontalScrollBarPolicy() == JScrollPane.SCROLLBAR_NEVER){
                    _local5.setVisible(false);
                    _local18 = 0;
                } else {
                    if (_local23.width <= _local22.width){
                        if (_local5.isEnabled()){
                            _local5.setEnabled(false);
                        };
                        if (_local2.getHorizontalScrollBarPolicy() != JScrollPane.SCROLLBAR_ALWAYS){
                            _local5.setVisible(false);
                            _local18 = 0;
                            _local3.setViewPosition(new IntPoint(0, _local3.getViewPosition().y));
                        } else {
                            _local5.setVisible(true);
                        };
                    } else {
                        _local5.setVisible(true);
                        if (!_local5.isEnabled()){
                            _local5.setEnabled(true);
                        };
                    };
                };
                if (_local18 != _local21){
                    _local3.setViewportTestSize(new IntDimension(_local8.width, (_local8.height - _local18)));
                    _local22 = _local3.getExtentSize();
                    _local23 = _local3.getViewSize();
                };
                if (_local2.getVerticalScrollBarPolicy() == JScrollPane.SCROLLBAR_NEVER){
                    _local4.setVisible(false);
                    _local14 = 0;
                } else {
                    if (_local23.height <= _local22.height){
                        _local4.setEnabled(false);
                        if (_local2.getVerticalScrollBarPolicy() != JScrollPane.SCROLLBAR_ALWAYS){
                            _local4.setVisible(false);
                            _local14 = 0;
                            _local3.setViewPosition(new IntPoint(_local3.getViewPosition().x, 0));
                        } else {
                            _local4.setVisible(true);
                        };
                    } else {
                        _local4.setVisible(true);
                        if (!_local4.isEnabled()){
                            _local4.setEnabled(true);
                        };
                    };
                };
                if (_local14 != _local20){
                    _local3.setViewportTestSize(new IntDimension((_local8.width - _local14), (_local8.height - _local18)));
                    _local22 = _local3.getExtentSize();
                    _local23 = _local3.getViewSize();
                };
                if ((((_local23.width > _local22.width)) && ((_local2.getHorizontalScrollBarPolicy() == JScrollPane.SCROLLBAR_AS_NEEDED)))){
                    if (!_local5.isVisible()){
                        _local5.setEnabled(true);
                        _local5.setVisible(true);
                        _local18 = _local10.height;
                        _local3.setViewportTestSize(new IntDimension((_local8.width - _local14), (_local8.height - _local18)));
                        _local22 = _local3.getExtentSize();
                        _local23 = _local3.getViewSize();
                    };
                };
                _local24 = _local8.x;
                _local25 = _local8.y;
                if (this.style == TOP_LEFT){
                    _local11 = _local8.x;
                    _local12 = (_local8.y + _local18);
                    _local13 = (_local8.height - _local18);
                    _local15 = (_local8.x + _local14);
                    _local16 = _local8.y;
                    _local17 = (_local8.width - _local14);
                    _local25 = (_local25 + _local18);
                    _local24 = (_local24 + _local14);
                } else {
                    if (this.style == TOP_RIGHT){
                        _local11 = ((_local8.x + _local8.width) - _local14);
                        _local12 = (_local8.y + _local18);
                        _local13 = (_local8.height - _local18);
                        _local15 = _local8.x;
                        _local16 = _local8.y;
                        _local17 = (_local8.width - _local14);
                        _local25 = (_local25 + _local18);
                    } else {
                        if (this.style == BOTTOM_LEFT){
                            _local11 = _local8.x;
                            _local12 = _local8.y;
                            _local13 = (_local8.height - _local18);
                            _local15 = (_local8.x + _local14);
                            _local16 = ((_local8.y + _local8.height) - _local18);
                            _local17 = (_local8.width - _local14);
                            _local24 = (_local24 + _local14);
                        } else {
                            _local11 = ((_local8.x + _local8.width) - _local14);
                            _local12 = _local8.y;
                            _local13 = (_local8.height - _local18);
                            _local15 = _local8.x;
                            _local16 = ((_local8.y + _local8.height) - _local18);
                            _local17 = (_local8.width - _local14);
                        };
                    };
                };
                if (_local4.isVisible()){
                    _local4.setComBoundsXYWH(_local11, _local12, _local14, _local13);
                };
                if (_local5.isVisible()){
                    _local5.setComBoundsXYWH(_local15, _local16, _local17, _local18);
                };
                _local19.setComBoundsXYWH(_local24, _local25, (_local8.width - _local14), (_local8.height - _local18));
                if (_local5.isVisible()){
                    _local5.setValues(Math.max(Math.min(_local5.getValue(), (_local23.width - _local22.width)), 0), _local22.width, 0, _local23.width);
                    _local5.setUnitIncrement(_local3.getHorizontalUnitIncrement());
                    _local5.setBlockIncrement(_local3.getHorizontalBlockIncrement());
                };
                if (_local4.isVisible()){
                    _local4.setValues(Math.max(Math.min(_local4.getValue(), (_local23.height - _local22.height)), 0), _local22.height, 0, _local23.height);
                    _local4.setUnitIncrement(_local3.getVerticalUnitIncrement());
                    _local4.setBlockIncrement(_local3.getVerticalBlockIncrement());
                };
            };
        }

    }
}//package org.aswing 
